#pragma once
#include <xpam/system/handle.h>

namespace xpam
{
    namespace system
    {
        class thread
        {
            void * _thread;
            static void run_internal(thread * th);
        protected:
            int _tid;
            int _stack_size;
            thread(int stack_size = 10240);
            virtual void procedure() = 0;
        public:
            virtual ~thread(void);

            void run();
            void pause();
            void terminate();
            void wait();
            void start() { run(); }

        public:
            static void sleep(int interval);
        };

        template<typename _Proc>
        class thread_wrapper : public _Proc, public thread
        {
        private:
            thread_wrapper() { };
        public:
            static thread_wrapper * create() { return new thread_wrapper(); }

            virtual void procedure()
            {
                static_cast<_Proc>(*this)();
            }
        };
    }
}